package com.huidao.servlet.goods;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.Goods;
import com.huidao.entity.User;
import com.huidao.service.GoodsService;
import com.huidao.service.GoodsServiceImpl;

/**
 * Servlet implementation class SellerGetGoodsListServlet
 */
public class SellerGetGoodsListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SellerGetGoodsListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int currentPage=1;
		if(request.getParameter("currentPage")!=null){
			currentPage=Integer.parseInt(request.getParameter("currentPage")); 			
		}
		//参数
		String namekey=request.getParameter("namekey");
		GoodsService g=new GoodsServiceImpl();
		
		int totalPage=g.getTotalCount(namekey);
		//当删除最后一页的唯一一条记录的时候
		if(currentPage>totalPage){
			currentPage = totalPage;
			}
		User user=(User) request.getSession().getAttribute("user");
		Long id=user.getUserId();
		List<Goods> list= g.getSellerListPage(currentPage, namekey, id);
			
		request.setAttribute("list",list);
		request.setAttribute("currentPage", currentPage);
		request.setAttribute("totalPage", totalPage);
		request.getRequestDispatcher("sellergoodslist.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
